<?php
class Card_model extends CI_Model {

	function __construct()
    {
        parent::__construct();
    }
    /**
	 * 获取点卡信息
	 * @param int $id
	 */
	public function find_by_id($id) {
		$this->db->where('id', $id);
		return $this->db->get('cards')->row_array();
	}
	/**
	 * 新增一张点卡，code随机
	 */
	public function add() {
	    list($usec, $sec) = explode(' ', microtime());
	    $rand_seed = (float) $sec + ((float) $usec * 100000);
		mt_srand($rand_seed);
		$randval = mt_rand();
		$code = md5(date("YmdHis") . $randval);
		$data = array('created' => date("Y-m-d H:i:s"), 'code' => $code);
		$this->db->insert("cards", $data);
		return $this->db->insert_id();
	}
}